/**
 * Created by wenquxing on 2016/5/18.
 */
var mysql  = require('mysql');  //调用MySQL模块



function connectServer(){
    //创建一个connection
    var connection = mysql.createConnection({
        host     : 'localhost',       //主机
        user     : 'root',               //MySQL认证用户名
        password : '123456',        //MySQL认证用户密码
        port: '3306',                   //端口号
        database:'node'
    });
   return connection;
}

exports.connect = connectServer;


//执行SQL语句
/*connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
    if (err) {
        console.log('[query] - :'+err);
        return;
    }
    console.log('The solution is: ', rows[0].solution);
});*/
/*
//关闭connection
connection.end(function(err){
    if(err){
        return;
    }
    console.log('[connection end] succeed!');
});
*/


/*
client.query(
    'select * from '+table,
    function selectCb(err,results,fields) {
        if(err){
            throw err;
        }
        if(results)
        {
            for(var i = 0; i < results.length; i++)
            {
                console.log("%s\t%s\t%s", results[i].id, results[i].nickname, results[i].email);
            }
        }
        client.end();
    }
)*/
//module.exports = connection;

/*connection.connect(function(err){
    if(err){
        console.log('[query] - :'+err);
        return callback(err);
    }
    console.log('[connection connect]  succeed!');
});*/

/*var  Sql = 'select t.name,t.password from t_user t where t.name= ?';
var  Sql_Params = ['1234'];
connection.query(Sql,Sql_Params,function (err, result) {
    if(err){
        connection.end();
    }

    if(result)
    {
        console.log(result);


    }else{

    }


});

connection.end();*/
